package com.bluegalaxy.nhb.snservice.common.config;

import com.google.common.collect.Lists;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;
import java.util.List;

/**
 * @Auther: nanhb
 * @Date: 2020/11/11 17:49
 * @Description:
 */
@Configuration
@EnableSwagger2
@ConditionalOnExpression("true") //开启访问接口文档的权限
public class SwaggerConfiguration {
//    @Bean
//    public Docket userRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("流程模块")  //模块名称
//                .apiInfo(apiInfo())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.bluegalaxy.nhb.ckapi.controller.api.ck.basicindicators"))  //扫描的控制器路径
//                .paths(PathSelectors.any())
//                .build();
//    }
    @Bean
    public Docket basicindicatorsDocket() {
        return docket("基础指标模块", "com.bluegalaxy.nhb.ckapi.controller.api.ck");
    }
//    @Bean
//    public Docket keepDocket() {
//        return docket("留存分析模块", "com.bluegalaxy.nhb.ckapi.controller.api.ck.KeepController");
//    }

    private Docket docket(String groupName, String basePackages) {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(groupName)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackages))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("xxx项目开发接口文档")    //接口文档标题
                .description("此文档仅供开发技术组领导、开发人员使用")   //描述
                .termsOfServiceUrl("http://www.xxx.com/")   //相关的网址
                .contact(new Contact("后端开发","http://www.xxx.com/","8xxxxx67@qq.com"))    //作者  邮箱等
                .version("1.0")  //版本号
                .build();
    }
}
